"""VMAF score regression using SVM"""

import json
import numpy as np
import torch


class SVMPredict(torch.nn.Module):
    def __init__(self, model_json_path=None, clip_score=False):
        super().__init__()

        self.clip_score = clip_score

        if model_json_path is not None:
            self.get_model_from_json(model_json_path)
        else:
            self.get_default_model()

    def forward(self, x):
        # normalize
        x = self.slopes * x + self.intercepts                                            # [batch_size, num_features]

        # svm predict
        x = x.reshape((-1, 1, self.num_features))  # make x broadcastable with support_vectors tensor
        k = torch.exp(-self.gamma*torch.sum((x - self.support_vectors)**2, dim=-1))      # K(x_i, x)
        s = torch.sum(self.alpha * k, dim=-1, keepdim=True)                              # \sigma_i \alpha_i K(x_i,x)
        pred = s - self.rho

        # denormalize
        pred = (pred - self.intercept) / self.slope

        # clip
        if self.clip_score:
            pred = torch.clip(pred, min=self.score_clip_min, max=self.score_clip_max)

        return pred

    def get_model_from_json(self, model_json_path):
        '''Load parameters for VMAF model from json file e.g. one of the files from https://github.com/Netflix/vmaf/tree/master/model
        (not guaranteed to work with every model since they have slightly different formats)
        '''

        with open(model_json_path) as f:
            self.model_json = json.load(f)

        intercepts = self.model_json['model_dict']['intercepts'][1:]                     # for feature normalization
        self.register_buffer('intercepts', torch.tensor(intercepts).to(torch.float32))
        self.intercept = self.model_json['model_dict']['intercepts'][0]                  # for score normalization

        slopes = self.model_json['model_dict']['slopes'][1:]                             # for feature normalization
        self.register_buffer('slopes', torch.tensor(slopes).to(torch.float32))
        self.slope = self.model_json['model_dict']['slopes'][0]                          # for score normalization

        self.gamma = float(self.model_json['model_dict']['model'].split('\n')[2].split()[1])
        self.rho = float(self.model_json['model_dict']['model'].split('\n')[5].split()[1])

        self.num_sv = int(self.model_json['model_dict']['model'].split('\n')[4].split()[1])

        self.score_clip_min = self.model_json['model_dict']['score_clip'][0]
        self.score_clip_max = self.model_json['model_dict']['score_clip'][1]

        # get support vectors and alpha
        alpha = []
        sv = []
        for data_str in self.model_json['model_dict']['model'].split('\n')[7:-1]:
            alpha.append(float(data_str.split()[0]))
            sv_str = data_str.split()[1:]
            sv_dict = {int(x.split(':')[0]): float(x.split(':')[1]) for x in sv_str}
            zero_dict = {x: 0. for x in range(1, 7)}
            sv_dict = {**zero_dict, **sv_dict}  # update missing values with zeros
            sv.append(np.array(list(sv_dict.values())))

        alpha = torch.tensor(np.stack(alpha)).to(torch.float32)                          # [211,]
        self.register_buffer('alpha', alpha)

        support_vectors = torch.tensor(np.stack(sv)).to(torch.float32)                   # [211, 6]
        self.num_features = support_vectors.shape[1]
        self.register_buffer('support_vectors', support_vectors)

    def get_default_model(self):
        '''Load parameters of default VMAF SVM model corresponding to https://github.com/Netflix/vmaf/blob/master/model/vmaf_v0.6.1.json'''

        self.num_features = 6
        self.num_sv = 211

        intercepts = torch.tensor([
            # -0.3092981927591963,
            -1.7993968597186747,
            -0.003017198086831897,
            -0.1728125095425364,
            -0.5294309090081222,
            -0.7577185792093722,
            -1.083428597549764
            ])
        self.register_buffer('intercepts', intercepts)         # for feature normalization
        self.intercept = -0.30929819275919629                  # for score normalization

        slopes = torch.tensor([
            # 0.012020766332648465,
            2.8098077502505414,
            0.06264407466686016,
            1.222763456258933,
            1.5360318811084146,
            1.7620864995501058,
            2.08656468286432
            ])
        self.register_buffer('slopes', slopes)                  # for feature normalization
        self.slope = 0.012020766332648465                       # for score normalization

        self.gamma = 0.04
        self.rho = -1.33133

        self.score_clip_min = 0
        self.score_clip_max = 100

        alpha = torch.tensor([
            -4.,                 4.,                 4.,                 4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                 4.,
             4.,                -4.,                -4.,                -4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                 4.,
            -4.,                -4.,                -4.,                -4.,                -4.,                -0.3312466607741135,
            -4.,                -4.,                -4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                -4.,                -4.,                -4.,                 4.,
             4.,                -4.,                -4.,                -4.,                -4.,                 4.,
            -4.,                 4.,                -4.,                 4.,                -4.,                 4.,
             4.,                 4.,                 4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                -4.,                -4.,                 4.,                -4.,
            -4.,                 4.,                 4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                -4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                -4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                 4.,                 1.296591709971377,  4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                -4.,
            -4.,                -4.,                -4.,                -4.,                -4.,                 4.,
             4.,                -4.,                -4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                 4.,                 4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                 4.,
            -4.,                 4.,                -4.,                -4.,                -4.,                -4.,
            -4.,                -4.,                 4.,                -4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                 4.,
             4.,                 4.,                -4.,                 4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                -3.795805084530972,
            -4.,                -4.,                -4.,                -4.,                 4.,                 0.4082706381617505,
            -4.,                -4.,                -4.,                -4.,                -4.,                -4.,
            -1.966116876631112, -3.906831378063804,  4.,                 4.,                 4.,                 4.,
             4.,                 4.,                 4.,                 4.,                 4.,                -4.,
             4.,                 4.,                 4.,                -4.,                 4.,                 4.,
             4.,                -4.,                 4.,                -4.,                 0.2951376518668717, 4.,
             4.,                -4.,                 4.,                 4.,                -4.,                -4.,
             4.,                 4.,                -4.,                 4.,                 4.,                -4.,
            -4.,                -4.,                -4.,                -4.,                -4.,                -4.,
            -4.
        ])
        self.register_buffer('alpha', alpha)

        support_vectors = torch.tensor([
            [0.65734273,   0.34681232,   0.093755557,  0.60913934,   0.69117362,   0.73495824,  ],
            [0.8727433,    0.49612229,   0.59146724,   0.78105663,   0.84916292,   0.8882561,   ],
            [0.89890005,   0.49612229,   0.66823667,   0.86050887,   0.90873162,   0.93335071,  ],
            [0.20371751,   0.49612229,   0.10534315,  -1.110223e-16, 0.,           2.220446e-16,],
            [0.33913836,   0.49612229,   0.14024497,   0.074708413,  0.10231651,   0.1259153,   ],
            [0.66426757,   0.49612229,   0.35268026,   0.4805681,    0.59603341,   0.67408692,  ],
            [0.59561632,   0.49612229,   0.27561601,   0.33977371,   0.4325213,    0.50244952,  ],
            [0.50821444,   0.49612229,   0.20276685,   0.2004308,    0.25758651,   0.30054029,  ],
            [0.77877298,   0.49612229,   0.444392,     0.61630491,   0.71210086,   0.77386496,  ],
            [0.71666017,   0.49612229,   0.35967401,   0.47825205,   0.57045236,   0.63752441,  ],
            [0.64025669,   0.49612229,   0.27766156,   0.33407105,   0.40732401,   0.46359154,  ],
            [0.88343983,   0.23066177,   0.65873851,   0.86090402,   0.90661213,   0.93008753,  ],
            [0.90822691,   0.23066177,   0.71439481,   0.90904598,   0.94146542,   0.95674338,  ],
            [0.49037399,   0.23066177,   0.32329421,   0.33686197,   0.39456977,   0.44944683,  ],
            [0.69044383,   0.23066177,   0.43933868,   0.56327049,   0.65339511,   0.71348696,  ],
            [0.62390093,   0.23066177,   0.3800888,    0.44927578,   0.52327759,   0.57907725,  ],
            [0.81887942,   0.23066177,   0.56208506,   0.76164281,   0.83176644,   0.86914911,  ],
            [0.77189471,   0.23066177,   0.50145055,   0.66525882,   0.74327951,   0.79017822,  ],
            [0.71405433,   0.23066177,   0.43952897,   0.55736023,   0.63319876,   0.68402869,  ],
            [0.92114073,   0.,           0.45198963,   0.97703695,   0.9907273,    0.99510256,  ],
            [1.,           0.,           0.83319067,   0.98956086,   0.99577089,   0.99784595,  ],
            [0.,           0.,           0.,           0.10344019,   0.34323945,   0.63855969,  ],
            [0.19531482,   0.,           0.034330388,  0.25480402,   0.54197045,   0.78020579,  ],
            [0.48394064,   0.,           0.11866359,   0.58816959,   0.86435738,   0.96191842,  ],
            [0.47628079,   0.,           0.11185039,   0.56180003,   0.83415721,   0.93617329,  ],
            [0.46278632,   0.,           0.10308547,   0.52247575,   0.78583924,   0.89392193,  ],
            [0.7038079,    0.,           0.2174879,    0.84423613,   0.9662906,    0.98430594,  ],
            [0.69596686,   0.,           0.20657211,   0.81196884,   0.94140702,   0.96680805,  ],
            [0.68404358,   0.,           0.19261438,   0.76066415,   0.89973293,   0.93660362,  ],
            [0.84073022,   0.34681232,   0.22411304,   0.88845644,   0.94169671,   0.96221395,  ],
            [0.33900937,   0.34681232,   0.027607294,  0.40659646,   0.45456869,   0.48256597,  ],
            [0.44593129,   0.34681232,   0.041939301,  0.45284872,   0.5157613,    0.55335821,  ],
            [0.67301747,   0.34681232,   0.11526222,   0.68549511,   0.78556255,   0.83507583,  ],
            [0.62833533,   0.34681232,   0.092281981,  0.61278125,   0.70626575,   0.75613977,  ],
            [0.57196879,   0.34681232,   0.067548447,  0.53383404,   0.61287548,   0.65468717,  ],
            [0.75125028,   0.34681232,   0.1457048,    0.75791308,   0.84155109,   0.88132116,  ],
            [0.71121936,   0.34681232,   0.12095689,   0.68834617,   0.77453583,   0.81892861,  ],
            [0.80269544,   0.25207203,   0.3681723,    0.80658472,   0.8702283,    0.90583519,  ],
            [0.86095387,   0.25207203,   0.52475418,   0.85053413,   0.90454501,   0.93093678,  ],
            [0.5008963,    0.25207203,   0.2005129,    0.41516485,   0.45282017,   0.47396143,  ],
            [0.56977992,   0.25207203,   0.21631076,   0.45848604,   0.51102137,   0.53823055,  ],
            [0.72779828,   0.25207203,   0.3051639,    0.67537297,   0.75767261,   0.80327187,  ],
            [0.68848569,   0.25207203,   0.27393051,   0.60399854,   0.68000038,   0.72275152,  ],
            [0.64121401,   0.25207203,   0.23994344,   0.52538719,   0.5891732,    0.62164073,  ],
            [0.76673633,   0.25207203,   0.33053889,   0.73085549,   0.80341439,   0.84546456,  ],
            [0.73041172,   0.25207203,   0.29691153,   0.66166141,   0.73408074,   0.77757209,  ],
            [0.68529047,   0.25207203,   0.26283557,   0.58611788,   0.65192525,   0.69015011,  ],
            [0.86902267,   0.48885268,   0.5143645,    0.8587242,    0.91841685,   0.94498293,  ],
            [0.89266106,   0.48885268,   0.55208861,   0.89938377,   0.94642982,   0.96615102,  ],
            [0.42554844,   0.48885268,   0.2554221,    0.36916892,   0.43100226,   0.50888404,  ],
            [0.52520274,   0.48885268,   0.27824915,   0.42915458,   0.50850476,   0.58585271,  ],
            [0.69357445,   0.48885268,   0.35289928,   0.61359907,   0.7217863,    0.78790011,  ],
            [0.64679648,   0.48885268,   0.31268451,   0.5167094,    0.61224976,   0.68477529,  ],
            [0.80595874,   0.48885268,   0.44075432,   0.7803455,    0.86328719,   0.90222545,  ],
            [0.7715192,    0.48885268,   0.4012577,    0.70792536,   0.80063653,   0.85083872,  ],
            [0.82199966,   0.20629643,   0.30562098,   0.80541317,   0.89285836,   0.92907353,  ],
            [0.84774006,   0.20629643,   0.36755712,   0.8681203,    0.93297792,   0.95700049,  ],
            [0.26631905,   0.20629643,   0.076468978,  0.29833807,   0.37989948,   0.4576277,   ],
            [0.65439648,   0.20629643,   0.19487894,   0.63045155,   0.76931142,   0.83706632,  ],
            [0.55295603,   0.20629643,   0.13877412,   0.4724047,    0.59295828,   0.66834832,  ],
            [0.75448924,   0.20629643,   0.24707248,   0.72284103,   0.83178838,   0.88053503,  ],
            [0.83852041,   0.15600331,   0.1625414,    0.81948421,   0.90185357,   0.9347395,   ],
            [0.85805266,   0.15600331,   0.19693206,   0.86294641,   0.92990351,   0.95498998,  ],
            [0.43384835,   0.15600331,   0.030541611,  0.37279112,   0.4588284,    0.52004828,  ],
            [0.72588966,   0.48885268,   0.35394597,   0.61189191,   0.70897304,   0.77099691,  ],
            [0.65865915,   0.20629643,   0.1796405,    0.56432133,   0.68049028,   0.74616621,  ],
            [0.53095193,   0.15600331,   0.046271684,  0.4328793,    0.5309142,    0.59282089,  ],
            [0.71891465,   0.15600331,   0.11085278,   0.68794624,   0.80350923,   0.85660483,  ],
            [0.68635753,   0.15600331,   0.091457045,  0.60849701,   0.72282659,   0.78137183,  ],
            [0.64162333,   0.15600331,   0.068820233,  0.51732819,   0.62198733,   0.67977328,  ],
            [0.78395225,   0.15600331,   0.13401869,   0.75274384,   0.8506531,    0.89321405,  ],
            [0.75276337,   0.15600331,   0.11289462,   0.67598462,   0.78117168,   0.83259364,  ],
            [0.71345342,   0.15600331,   0.089218917,  0.58797907,   0.69284768,   0.74971699,  ],
            [0.93500967,   0.08765484,   0.72226864,   0.93291747,   0.960644,     0.97304054,  ],
            [0.95150668,   0.08765484,   0.77391346,   0.95596295,   0.97544784,   0.98405871,  ],
            [0.48148634,   0.08765484,   0.36628046,   0.45852823,   0.56005228,   0.65708595,  ],
            [0.59853216,   0.08765484,   0.42071301,   0.56376512,   0.66454599,   0.741236,    ],
            [0.79297271,   0.08765484,   0.5597726,    0.80653689,   0.88996341,   0.92691132,  ],
            [0.76798941,   0.08765484,   0.52069978,   0.74484555,   0.83431246,   0.87935204,  ],
            [0.73225133,   0.08765484,   0.47011786,   0.66069877,   0.75226598,   0.80539407,  ],
            [0.87240592,   0.08765484,   0.62680052,   0.88208508,   0.93041565,   0.9505376,   ],
            [0.84834872,   0.08765484,   0.58154998,   0.82429855,   0.8858516,    0.91563291,  ],
            [0.84365382,   0.93973481,   0.36718425,   0.81512123,   0.88887359,   0.92320992,  ],
            [0.89242364,   0.93973481,   0.41336953,   0.88038833,   0.93688884,   0.95992879,  ],
            [0.31373571,   0.93973481,   0.18757116,   0.34864297,   0.3777168,    0.38922611,  ],
            [0.42490775,   0.93973481,   0.20295859,   0.39290035,   0.43632323,   0.45871216,  ],
            [0.66865444,   0.93973481,   0.28594627,   0.63969879,   0.73360583,   0.78380069,  ],
            [0.62642524,   0.93973481,   0.26141889,   0.56602175,   0.64775366,   0.69263211,  ],
            [0.57430455,   0.93973481,   0.23537634,   0.48984694,   0.55363885,   0.5853905,   ],
            [0.76178555,   0.93973481,   0.32205372,   0.7176044,    0.80237787,   0.84588741,  ],
            [0.72282163,   0.93973481,   0.29554025,   0.64471949,   0.72634443,   0.77062686,  ],
            [0.67693861,   0.93973481,   0.2669659,    0.56720118,   0.63868728,   0.67673331,  ],
            [0.86023804,   0.49739676,   0.53966638,   0.77392585,   0.84784447,   0.89031641,  ],
            [0.31779385,   0.49739676,   0.17094319,   0.12195679,   0.13277563,   0.14165413,  ],
            [0.68317784,   0.49739676,   0.37192301,   0.52750491,   0.62426522,   0.6929947,   ],
            [0.55611181,   0.49739676,   0.24752355,   0.28326524,   0.33261781,   0.37104424,  ],
            [0.7772257,    0.49739676,   0.43832146,   0.63397606,   0.7240692,    0.78367237,  ],
            [0.66186286,   0.49739676,   0.30599867,   0.39201262,   0.45927759,   0.51239284,  ],
            [0.94601776,   0.04579546,   0.69472114,   0.97790884,   0.9891237,    0.993277,    ],
            [0.98838404,   0.04579546,   0.90293444,   0.99181622,   0.99642641,   0.9978864,   ],
            [0.30006056,   0.04579546,   0.31879,      0.45852885,   0.59717781,   0.71487885,  ],
            [0.44902891,   0.04579546,   0.35412414,   0.55926446,   0.70175505,   0.79649177,  ],
            [0.69856222,   0.04579546,   0.45989947,   0.82115248,   0.92520734,   0.9594384,   ],
            [0.67730161,   0.04579546,   0.44400319,   0.77920819,   0.88713866,   0.92903178,  ],
            [0.64419192,   0.04579546,   0.42297435,   0.72390263,   0.83364665,   0.88344569,  ],
            [0.80781899,   0.04579546,   0.52334234,   0.88859427,   0.94013924,   0.95946903,  ],
            [0.78080761,   0.04579546,   0.499439,     0.84012074,   0.90229375,   0.92936693,  ],
            [0.97128596,   0.014623935,  0.90135809,   0.99584619,   0.9970631,    0.99757649,  ],
            [0.99645027,   0.014623935,  1.,           1.,           1.,           1.,          ],
            [0.5326065,    0.014623935,  0.75468972,   0.76017077,   0.83753774,   0.92265059,  ],
            [0.62757004,   0.014623935,  0.77708563,   0.84258654,   0.91016348,   0.95440359,  ],
            [0.79306842,   0.014623935,  0.78900741,   0.90386551,   0.96905764,   0.98466408,  ],
            [0.77722867,   0.014623935,  0.78701408,   0.89679281,   0.96056131,   0.977629,    ],
            [0.75934622,   0.014623935,  0.78422805,   0.88268036,   0.94383829,   0.96596858,  ],
            [0.8878718,    0.014623935,  0.81445984,   0.96615706,   0.98858241,   0.99176534,  ],
            [0.88211614,   0.014623935,  0.81253935,   0.95982371,   0.98309178,   0.9870796,   ],
            [0.83805466,   0.22767235,   0.31750162,   0.85145925,   0.9121085,    0.93772147,  ],
            [0.86620985,   0.22767235,   0.35742938,   0.89821492,   0.94339974,   0.96076173,  ],
            [0.39289606,   0.22767235,   0.12019254,   0.3951559,    0.44657802,   0.46771549,  ],
            [0.48692411,   0.22767235,   0.13362033,   0.43434224,   0.49900609,   0.53177669,  ],
            [0.69743918,   0.22767235,   0.2263303,    0.68859985,   0.78706365,   0.83662428,  ],
            [0.65237548,   0.22767235,   0.19328493,   0.60107975,   0.69684945,   0.74949279,  ],
            [0.59461718,   0.22767235,   0.15963705,   0.51010642,   0.59283393,   0.63883591,  ],
            [0.77302727,   0.22767235,   0.26078021,   0.76359704,   0.8470807,    0.8858359,   ],
            [0.72953038,   0.22767235,   0.22331233,   0.67735915,   0.77029889,   0.81802539,  ],
            [0.87210923,   0.16787772,   0.69408521,   0.91495146,   0.94890261,   0.96269344,  ],
            [0.81595959,   0.08765484,   0.52947327,   0.7501341,    0.82294191,   0.86264385,  ],
            [0.72562415,   0.49739676,   0.37130724,   0.51472366,   0.59961357,   0.66258291,  ],
            [0.87135693,   0.014623935,  0.80905852,   0.94637428,   0.97242826,   0.97946694,  ],
            [0.48910215,   0.16787772,   0.49792761,   0.59161372,   0.62979552,   0.64254584,  ],
            [0.5685964,    0.16787772,   0.5149767,    0.63026581,   0.67890679,   0.69964851,  ],
            [0.75935478,   0.16787772,   0.60695536,   0.80906778,   0.87125816,   0.89810007,  ],
            [0.71788601,   0.16787772,   0.57600091,   0.75310216,   0.81471966,   0.84249923,  ],
            [0.66516668,   0.16787772,   0.54473368,   0.69254626,   0.74796983,   0.77177867,  ],
            [0.81880869,   0.16787772,   0.64309172,   0.86078024,   0.90892223,   0.92908907,  ],
            [0.78054558,   0.16787772,   0.60849279,   0.80724494,   0.86183239,   0.88618408,  ],
            [0.95353512,   0.055921852,  0.61526026,   0.94655706,   0.97211195,   0.98210701,  ],
            [0.98368527,   0.055921852,  0.7405327,    0.96928567,   0.9853799,    0.99080378,  ],
            [0.11318821,   0.055921852,  0.1590151,    0.30536689,   0.48614515,   0.64344462,  ],
            [0.30298819,   0.055921852,  0.19401703,   0.41679982,   0.61495039,   0.74140301,  ],
            [0.60614412,   0.055921852,  0.31791569,   0.72365433,   0.88324129,   0.93484545,  ],
            [0.58738733,   0.055921852,  0.29301498,   0.67070014,   0.83429953,   0.89348041,  ],
            [0.79496816,   0.055921852,  0.42192974,   0.86711004,   0.94030868,   0.96084539,  ],
            [0.77749763,   0.055921852,  0.38714172,   0.81340799,   0.90059649,   0.93006702,  ],
            [0.75215882,   0.055921852,  0.34721658,   0.73960747,   0.84370247,   0.88485372,  ],
            [0.89732805,   0.58937038,   0.58823535,   0.80035053,   0.86988422,   0.90533033,  ],
            [0.9228759,    0.58937038,   0.65797705,   0.87169952,   0.92200942,   0.94454256,  ],
            [0.19504362,   0.58937038,   0.21585801,   0.1754362,    0.20844015,   0.23846443,  ],
            [0.34425894,   0.58937038,   0.24672569,   0.24188506,   0.29544562,   0.33843061,  ],
            [0.66407117,   0.58937038,   0.40045124,   0.55415203,   0.66628031,   0.73418465,  ],
            [0.60780044,   0.58937038,   0.34931828,   0.4519606,    0.54893247,   0.61355219,  ],
            [0.53476258,   0.58937038,   0.29851601,   0.34826788,   0.42168642,   0.47203603,  ],
            [0.79195776,   0.58937038,   0.47493233,   0.66775916,   0.76196439,   0.81489875,  ],
            [0.7415564,    0.58937038,   0.41507439,   0.56413083,   0.65815516,   0.7166999,   ],
            [0.82021207,   1.,           0.37381485,   0.7891612,    0.87031145,   0.90944281,  ],
            [0.85903236,   1.,           0.43235998,   0.86707094,   0.92632217,   0.95151451,  ],
            [0.25243046,   1.,           0.084027451,  0.15537936,   0.17410072,   0.17212333,  ],
            [0.35643487,   1.,           0.10644455,   0.21484368,   0.25587544,   0.27527817,  ],
            [0.57605414,   1.,           0.19031962,   0.43030863,   0.5277316,    0.59069772,  ],
            [0.49071444,   1.,           0.14452095,   0.31406915,   0.38353445,   0.42653517,  ],
            [0.73255545,   1.,           0.28883701,   0.65284485,   0.75623242,   0.81297442,  ],
            [0.67015395,   1.,           0.2367756,    0.5367057,    0.64063877,   0.70451767,  ],
            [0.84450653,   0.083369236,  0.57279245,   0.85249389,   0.91751611,   0.94621989,  ],
            [0.39559773,   0.083369236,  0.28184137,   0.37025203,   0.46733936,   0.53517338,  ],
            [0.70621493,   0.083369236,  0.42718441,   0.69347659,   0.81124449,   0.87136343,  ],
            [0.65615861,   0.083369236,  0.37833052,   0.59301482,   0.71772587,   0.7905538,   ],
            [0.58837863,   0.083369236,  0.33229353,   0.48675881,   0.60141743,   0.67458413,  ],
            [0.77687144,   0.083369236,  0.48094343,   0.76665994,   0.86191893,   0.90760934,  ],
            [0.72849768,   0.083369236,  0.42082971,   0.66591147,   0.77995959,   0.84260661,  ],
            [0.66320082,   0.083369236,  0.36350305,   0.54888271,   0.66506794,   0.73685112,  ],
            [0.84500499,   0.42532178,   0.43562507,   0.80721931,   0.87934044,   0.91434143,  ],
            [0.8874543,    0.42532178,   0.50912639,   0.87959883,   0.93223488,   0.95450335,  ],
            [0.31032192,   0.42532178,   0.18976794,   0.30662908,   0.34637104,   0.3661022,   ],
            [0.41026349,   0.42532178,   0.20589097,   0.35241209,   0.40358156,   0.42577381,  ],
            [0.67552108,   0.42532178,   0.30879992,   0.60375124,   0.70097073,   0.75507206,  ],
            [0.62772585,   0.42532178,   0.27349745,   0.5196735,    0.60339149,   0.65103342,  ],
            [0.5741386,    0.42532178,   0.24033766,   0.43855753,   0.50243186,   0.53322825,  ],
            [0.7629976,    0.42532178,   0.35347476,   0.69239941,   0.78245146,   0.83117443,  ],
            [0.71746409,   0.42532178,   0.31296983,   0.60525302,   0.69243388,   0.7432587,   ],
            [0.73137955,   0.16787772,   0.57222383,   0.74405775,   0.79993424,   0.82484891,  ],
            [0.67383121,   0.58937038,   0.35481019,   0.45269287,   0.53578336,   0.59116487,  ],
            [0.5905971,    1.,           0.18559792,   0.41535212,   0.50422336,   0.56173557,  ],
            [0.66157018,   0.42532178,   0.27479904,   0.51802649,   0.59270541,   0.63560969,  ],
            [0.66827754,   0.54342577,   0.18169339,   0.50290989,   0.59875259,   0.65332628,  ],
            [0.85027066,   0.20820673,   0.40997978,   0.82462749,   0.89794736,   0.93142825,  ],
            [0.87892054,   0.20820673,   0.45891267,   0.87823329,   0.93535353,   0.95883927,  ],
            [0.3986268,    0.20820673,   0.17753958,   0.33495583,   0.39777832,   0.44399359,  ],
            [0.48997993,   0.20820673,   0.20172681,   0.39715881,   0.47368229,   0.52781628,  ],
            [0.7022939,    0.20820673,   0.31094767,   0.6676259,    0.77726116,   0.83518027,  ],
            [0.65773092,   0.20820673,   0.27420721,   0.57889989,   0.68485118,   0.74837036,  ],
            [0.60031736,   0.20820673,   0.23419121,   0.48018865,   0.57200972,   0.63197473,  ],
            [0.77623676,   0.20820673,   0.3510016,    0.74206651,   0.83508543,   0.88101902,  ],
            [0.73562396,   0.20820673,   0.31004997,   0.6557112,    0.75585014,   0.81164989,  ],
            [0.67923081,   0.20820673,   0.26679137,   0.55816547,   0.65579282,   0.71593631,  ],
            [0.83968539,   0.54342577,   0.32439292,   0.78747769,   0.87303614,   0.91271252,  ],
            [0.86656342,   0.54342577,   0.37898741,   0.85252726,   0.92049615,   0.94848246,  ],
            [0.42728303,   0.54342577,   0.10123262,   0.31581962,   0.38571265,   0.42827036,  ],
            [0.63194526,   0.54342577,   0.18169045,   0.51611903,   0.62179755,   0.68216176,  ],
            [0.56954706,   0.54342577,   0.14271477,   0.41491191,   0.50173488,   0.55220392,  ],
            [0.76753176,   0.54342577,   0.26295318,   0.6905031,    0.79291823,   0.84469464,  ],
            [0.72348649,   0.54342577,   0.22334634,   0.60145902,   0.70573225,   0.76318544,  ],
            [0.83584492,   0.047285912,  0.53826775,   0.933335,     0.95948954,   0.96870909,  ],
            [0.85530855,   0.047285912,  0.55323777,   0.95113339,   0.97249918,   0.9795177,   ],
            [0.53835734,   0.047285912,  0.41965074,   0.71632669,   0.73953043,   0.73487553,  ],
            [0.59175144,   0.047285912,  0.43113594,   0.74141738,   0.76929188,   0.77018949,  ],
            [0.75962366,   0.047285912,  0.49613729,   0.87838146,   0.91688438,   0.93150362,  ],
            [0.72043129,   0.047285912,  0.47217411,   0.83138845,   0.8704229,    0.88419439,  ],
            [0.67287449,   0.047285912,  0.44652268,   0.77691812,   0.81043483,   0.8177009,   ],
            [0.8023177,    0.047285912,  0.51559706,   0.90512389,   0.93743101,   0.9492968,   ],
            [0.76751376,   0.047285912,  0.49225957,   0.86357299,   0.89948127,   0.91221155,  ],
            [0.72124785,   0.047285912,  0.46606653,   0.81323145,   0.84847474,   0.85892657,  ],
        ])
        self.register_buffer('support_vectors', support_vectors)
